<script setup lang="ts">
import { ref } from "vue";
import { formRules } from "../utils/rule";
import { FormProps } from "../utils/types";
import { DictSelect } from "@/components/common/DictSelect";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    id: "",
    categoryName: "",
    categoryCode: "",
    parentId: undefined,
    type: undefined,
    sort: undefined,
    parentList: []
  })
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="100px"
  >
    <el-row>
      <el-col :span="16" class="m-auto">
        <el-form-item label="类目名称" prop="categoryName">
          <el-input
            v-model="newFormInline.categoryName"
            clearable
            placeholder="请输入类目名称"
          />
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="16" class="m-auto">
        <el-form-item label="类目编码" prop="categoryCode">
          <el-input
            v-model="newFormInline.categoryCode"
            clearable
            placeholder="请输入类目编码"
          />
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="16" class="m-auto">
        <el-form-item label="上级类目" prop="parentId">
          <el-tree-select
            v-model="newFormInline.parentId"
            :data="newFormInline.parentList"
            check-strictly
            default-expand-all
            :render-after-expand="false"
            class="!w-[full]"
          />
          <!-- <el-select
            v-model.number="newFormInline.parentId"
            clearable
            placeholder="请选择上级类目"
            class="!w-[full]"
          >
            <el-option
              v-for="item in newFormInline.parentList"
              :key="item.id"
              :label="item.categoryName"
              :value="item.id"
            />
          </el-select> -->
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="16" class="m-auto">
        <el-form-item label="商品类型" prop="type">
          <DictSelect
            v-model="newFormInline.type"
            dict-type="PRODUCT_TYPE"
            clearable
          />
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="16" class="m-auto">
        <el-form-item label="排序" prop="sort">
          <el-input
            v-model="newFormInline.sort"
            clearable
            placeholder="请输入排序"
          />
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>
